package com.yanqu.road.server.cmd.activity.banquet;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.BanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.banquet.CrossBanquetAutoOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = BanquetProto.AutoBanquetSettingForActivityReqMsg.class, respMsg = BanquetProto.AutoBanquetSettingForActivityRespMsg.class)
@Cmd(code = GameProtocol.S_BANQUET_ACTIVITY_AUTO_SETTING, desc = "自动开宴（开始、结束）")
public class AutoBanquetSettingForActivityCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        BanquetProto.AutoBanquetSettingForActivityReqMsg msg = BanquetProto.AutoBanquetSettingForActivityReqMsg.parseFrom(packet.getBytes());
        int times = 0;
        if(msg.hasTimes()){
            times = msg.getTimes();
        }
        if(msg.getOpt() != 1 && (times <= 0 || times > 10000000)){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }
        ret = CrossBanquetAutoOpenMgr.autoOpenSetting(player, msg.getOpt(), msg.getType(), times);
    }

    @Override
    public void sendData(GamePlayer player) {
       if(ret != 0){
           BanquetProto.AutoBanquetSettingForActivityRespMsg.Builder clientMsg = BanquetProto.AutoBanquetSettingForActivityRespMsg.newBuilder();
           clientMsg.setRet(ret);
           player.sendPacket(Protocol.U_BANQUET_ACTIVITY_AUTO_SETTING, clientMsg);
       }
    }
}
